<?php 
/**
 * 数据库备份管理控制器
 */
class BackUpController extends AuthController{
	/**
	 * 备份列表
	 */
	public function index(){
		$dirArr = Dir::tree('Backup');
		$this->assign('dirArr',$dirArr);
	    $this->display();
	}
	/**
	 * 备份数据库
	 */
	public function add(){
		$result = Backup::backup(
			array(
				'size' => 200,
				'dir' => 'Backup/' . date('ymdHis'),
				'step_time' => 1
			)
		);
		//如果备份发生错误
		if($result === false){
			$this->error(Backup::$error, U('Index/index'));
		}else{
			 if($result['status'] == 'success') {
			 	 //备份完成 
			 	$this->success('备份成功',U('index'));
			 }else{
			 	//备份过程中 
			 	$this->success($result['message'], $result['url'],0.2); 
			 }
		}
	}
	
	/**
	 * 还原
	 */
	public function recovery(){
		//备份目录 
		if(!isset($_SESSION['dir'])){
			$_SESSION['dir'] = Q('post.dir');
		}
		$result = Backup::recovery(array('dir' => $_SESSION['dir'])); 
		//还原发生错误
		if($result === false) {
			 $this->error(Backup::$error, U('index')); 
		}else{
			//还原完毕
			if($result['status'] == 'success'){
				unset($_SESSION['dir']);
				$this->success($result['message'], U('index'));
			}else{
				//还原过程中
				$this->success($result['message'], $result['url'], 0.2);
			}
		}
	}
	
	
}






